﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices.WindowsRuntime;
using Windows.Foundation;
using Windows.Foundation.Collections;
using Windows.UI.Popups;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Controls.Primitives;
using Windows.UI.Xaml.Data;
using Windows.UI.Xaml.Input;
using Windows.UI.Xaml.Media;
using Windows.UI.Xaml.Navigation;

// The Blank Page item template is documented at http://go.microsoft.com/fwlink/?LinkId=402352&clcid=0x409

namespace uWPIcons
{
    /// <summary>
    /// Refs:
    /// https://msdn.microsoft.com/query/dev14.query?appId=Dev14IDEF1&l=EN-US&k=k(Windows.UI.Xaml.Controls.Symbol);k(TargetFrameworkMoniker-.NETCore,Version%3Dv5.0);k(DevLang-csharp)&rd=true
    /// https://msdn.microsoft.com/en-us/windows/uwp/controls-and-patterns/segoe-ui-symbol-font
    /// https://msdn.microsoft.com/en-us/library/jj662743.aspx
    /// </summary>
    public sealed partial class MainPage : Page
    {
        public MainPage()
        {
            this.InitializeComponent();
        }

        protected override void OnNavigatedTo(NavigationEventArgs e)
        {

            IEnumerable<Symbol> query = Enum.GetValues(typeof(Symbol)).Cast<Symbol>();
            _EnumArrayProp = query.ToList<Symbol>();

            //Symbol[] sy = query.ToArray<Symbol>();
            //var query2 = sy.Select
            //    ((icon, index) => new Inconz { Num = index, Icon = icon, Name = icon.ToString() });
            //Iconzz = query2.ToList<Inconz>();
            Unknown.IsChecked = true;
            ToggleDataContext();
        }

        private List<Symbol> _EnumArrayProp;
        public List<Symbol> EnumArrayProp
        {
            get { return _EnumArrayProp; }
        }

        //public List<Inconz> Iconzz;

        //public class Inconz
        //{
        //    public int Num;
        //    public Symbol Icon;
        //    public string Name;
        //}






        public string Icon1Name { get { return _icon1.ToString(); } }
        public uint Icon1Value { get { return (uint)_icon1; } }

        //public void SetDecision()
        //{

        //    if (_Decision== Decision.Yes)
        //    {
        //        _icon = Symbol.Accept;
        //    }
        //    else if (_Decision == Decision.No)
        //    {
        //        _icon =  Symbol.Cancel;
        //    }
        //    else if (_Decision == Decision.Unknown)
        //    {
        //        _icon = Symbol.Stop;
        //    }
        //    else
        //    {
        //        System.Diagnostics.Debug.WriteLine("_Decision Icon Invalid State.");
        //        throw new Exception("_Decision Icon Invalid State.");
        //    }

        //}


        public Symbol Icon2
        {
            get
            {
                if (_Decision == Decision.Yes)
                {
                    return Symbol.Accept;
                }
                else if (_Decision == Decision.No)
                {
                    return Symbol.Cancel;
                }
                else if (_Decision == Decision.Unknown)
                {
                    return Symbol.Stop;
                }
                else
                    return Symbol.Stop;
            }
        }
        public enum Decision
        {
            Yes,
            No,
            Unknown
        }

        public static Decision _Decision { get; set; } = Decision.Unknown;

        private void Decision_Checked(object sender, RoutedEventArgs e)
        {
            RadioButton rb = (RadioButton)sender;
            if (rb != null)
            {
                switch (rb.Name)
                {
                    case "Yes":
                        _Decision = Decision.Yes;
                        break;
                    case "No":
                        _Decision = Decision.No;
                        break;
                    case "Unknown":
                        _Decision = Decision.Unknown;
                        break;
                }
                //SetDecision();
                ToggleDataContext();
            }
        }

        private async void buttonCamera_Tapped(object sender, TappedRoutedEventArgs e)
        {
            Button button = (Button)sender;
            if (sender != null)
            {
                string str = button.Name;
                var messageDialog = new MessageDialog(str +" pressed.");
                await messageDialog.ShowAsync();
            }
        }

        Symbol _icon1 = Symbol.Stop;
        public Symbol Icon1 { get { return _icon1; } }

        private void Next_Tapped(object sender, TappedRoutedEventArgs e)
        {
            _icon1 = (Symbol) ( 1+ (uint)_icon1 );
            ToggleDataContext();
        }

        private void Prev_Tapped(object sender, TappedRoutedEventArgs e)
        {
            _icon1 = (Symbol)( ((uint)_icon1) -1);
            ToggleDataContext();

        }

        private void ToggleDataContext()
        {
            MainGrid.DataContext = null;
            MainGrid.DataContext = this;
            ListIconz.DataContext =EnumArrayProp;
        }

        private void ListIconz_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            if (ListIconz.SelectedIndex != -1)
            {
                Symbol sym = (Symbol)ListIconz.SelectedItem;
                _icon1 = sym;
                ToggleDataContext();
            }
        }

        private async void AppBarButton_Click(object sender, RoutedEventArgs e)
        {
            AppBarButton button = (AppBarButton)sender;
            if (sender != null)
            {
                string str = button.Name;
                var messageDialog = new MessageDialog(str + " pressed.");
                await messageDialog.ShowAsync();
            }
        }


    }
}
 